﻿/* Description: jQuery Legend plugin
//* Created On: 05-Sep-2011
//* Created By: Senthilnathan 
//* Last Modified On: 
//* Last Modified By:
//* Last Modified Reason:
Example Usage:
$("#phLegend").legend({ gray: "#6e6e6e", orange: "#f78d1d"});
Where
    1) #phLegend -> Any dom element. Legend will be attached next to this element in the Dom tree
    2) config -> Javascript object as key, value pairs i.e. { gray: "#6e6e6e", orange: "#f78d1d"}
    
    Note: Call this in the page load complete event.
    Complete example with Jquery on Dom ready (page load complete)
     $(function() {$("#phLegend").legend({ gray: "#6e6e6e", orange: "#f78d1d"});});
*/
(function($) {
$.fn.legend = function(config) {    
        //config = $.extend({}, $.fn.legend.defaults, config);
        this.each(function() {
            var spnLegends = "";
            jQuery.each(config, function(key, value) {                   
                    spnLegends += "<span style='font: 10pt;font-family: Arial;padding: 0px 4px;border-left: 6px solid " + value + ";'>" + key + "</span>";
                });
                $(this).after(spnLegends).next();
        });
    }    
    $.fn.legend.defaults = { gray: "#6e6e6e", orange: "#f78d1d", blue: "#0095cd", rosy: "#da5867", green: "#64991e", pink: "#f895c2", red : "#d81b21" };
})(jQuery);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*Form Group Title ()*/
(function($) {
$.fn.grouptitle = function(config) {
        var html = '<table class="vm-frm-title ' + config.classname + ' id=""><tbody><tr><td>' + config.title + '</td></tr></tbody></table>';
        $(this).append(html);
    };
})(jQuery);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*LinkedInStyleTitle ()*/
(function($) {
$.fn.linkedInStyleTitle = function(config) {
        var html = "";
        html += '<div class="' + config.classname + '" id="title_' + config.id + '">'
        html += (config.close) ? '<button class="close" id="close_' + config.id + '"/>' : '';
        html += '<p>' + config.title + '</p>'
        html += '</div>'
        $(this).append(html);
    };
})(jQuery);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*Yarnlet ()*/
(function($) {
    $.fn.yarnlet = function(config) {
        var pfx = '<div id="yarnball"><ul class="yarnball">';
        var sfx = '</ul></div>';
        var que = config;
        var res = '';
        var flag = false;
        jQuery.each(que.steps, function(key, value) {
            var className = "";
            if (!flag) {
                if (que.current == value) { className = "current"; flag = true; } else { className = "past"; }
            }
            else {className = "future";}
            if (key == 0) {
                var con = '<li class="yarnlet first"><a  class="' + className + '" href="#" style="z-index: ' + String(parseInt(que.steps.length) - parseInt(key)) + ';"><span class="left-yarn"></span>' + value + '</a></li>';
                res += pfx;
                res += con;
            } else {
                var con = '<li class="yarnlet"><a class="topic-link ' + className + '" href="#" style="z-index: ' + String(parseInt(que.steps.length) - parseInt(key)) + ';">' + value + '</a></li>';
                res += con;
            }
        });
        res += sfx;
        $(this).append(res);
    };
})(jQuery);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*Slider Button*/
(function($) {
$.fn.attachSliderButton = function(parent) {
       var pc = this.selector;
        var collapsepath = _absWebRoot + "Images/"
        var ImgOpenWrap = { Exapnd: collapsepath + "expand_btn.jpg", Collapse: collapsepath + "collapse_btn.jpg" }

        $.get(_absWebRoot + "HtmlTemplates/plugins/openwrap.htm", function(template) {

            $.tmpl(template, ImgOpenWrap).insertAfter(pc);

            $(".topMenuAction").click(function() {
                if ($("#searchForm").is(":hidden")) {
                    $("#searchForm").slideDown("slow");
                    $("#topMenuImage").html("<img src='" + ImgOpenWrap.Collapse + "' alt='open' />");
                    $("#openCloseWrap").css("margin-top", "4px");
                    $("#openCloseWrap").css("margin-left", "94px");
                } else {
                    $("#searchForm").slideUp("slow");
                    $("#topMenuImage").html("<img src='" + ImgOpenWrap.Exapnd + "' alt='open' />");
                    $("#openCloseWrap").css("margin-top", "9px");
                    $("#openCloseWrap").css("margin-left", "94px");
                }
            });
        });
    }
})(jQuery);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*Accordian Menu 
Reference: http://www.i-marco.nl/weblog/jquery-accordion-menu-redux/
*/
(function($) {
$.fn.MakeAccordian = function(config) {
           $('ul.menu ul').hide();
    $.each($('ul.menu'), function () {
        $('#' + this.id + '.expandfirst ul:first').show();
    });
    $('ul.menu li a').click(
    function () {
        var checkElement = $(this).next();
        var parent = this.parentNode.parentNode.id;
        if ($('#' + parent).hasClass('noaccordion')) {
            $(this).next().slideToggle('normal');
            return false;
        }
        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            if ($('#' + parent).hasClass('collapsible')) {
                $('#' + parent + ' ul:visible').slideUp('normal');
            }
            return false;
        }
        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $('#' + parent + ' ul:visible').slideUp('normal');
            checkElement.slideDown('normal');
            return false;
        }
    });
    };
})(jQuery);